package com.vincent.sciinfo.service.impl;

import com.vincent.sciinfo.mapper.TakeMeetingMapper;
import com.vincent.sciinfo.pojo.TakeMeeting;
import com.vincent.sciinfo.service.TakeMeetingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TakeMeetingServiceImpl implements TakeMeetingService {

    @Autowired
    private TakeMeetingMapper takeMeetingMapper;

    @Override
    public List<TakeMeeting> selectByMeetingId(Integer meetingid) {
        return takeMeetingMapper.selectByMeetingId(meetingid);
    }

    @Override
    public int takeMeeting(int meetingid, String teacherId) {
        int data = 2;
        //1. 是否该教师已经参加该会议 data为2表示已经加入
        TakeMeeting takeMeeting = takeMeetingMapper.selectOne(meetingid, teacherId);
        if (takeMeeting != null) return data;

        //2.联系表中插入会议与教师的信息 data为1表示加入成功 data为0表示加入失败
        data = takeMeetingMapper.insertOne(meetingid, teacherId);
        return data;
    }
}
